import fetcher from "../apis/Fetcher";
import {Page, Pageable} from "../utils/Page";
import {NumberIdAndName} from "../types/BasicModels";

export interface QueryMarketsRequest {
    name?: string
}

export function queryMarkets(queryMarketsRequest: QueryMarketsRequest, pageable: Pageable) {
    return fetcher.get<Page<QueryMarketsResponse>>("/markets", {...queryMarketsRequest, ...pageable.toRequestParams()})
}

export interface QueryMarketsResponse{
    id:number
    name:string
    saleManager?:NumberIdAndName
    excludeBrands: NumberIdAndName[]
    shoppingGuides:NumberIdAndName[]
    goodsAmount:number
}

export interface CreateMarketRequest{
    name:string
    saleManagerId?:number
    excludeBrandIds:number[]
    shoppingGuideIds:number[]
}

export function createMarket(createMarketRequest:CreateMarketRequest){
    return fetcher.post<number>("markets",{},createMarketRequest)
}

export function updateMarket(id:number,createMarketRequest:CreateMarketRequest){
    return fetcher.put(`markets/${id}`,{},createMarketRequest)
}

export function getAllMarket(){
    return fetcher.get<Array<NumberIdAndName>>("markets")
}

export function getMarketDetail(id:number){
    return fetcher.get<MarketDetailResponse>(`markets/${id}`)
}

export interface MarketDetailResponse {
    id:number
    name:string
    saleManager?:NumberIdAndName
    excludeBrands: NumberIdAndName[]
    shoppingGuides:NumberIdAndName[]
    goodsAmount:number
    orderAmount:number
}

export function getAllMarketsOnlyICanSee(){
    return fetcher.get<Array<NumberIdAndName>>("markets",{
        onlyICanSee:true
    })
}